package top.cross.webapp.common.plugin;

import android.util.Log;
import android.widget.Toast;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;
import java.util.Calendar;

import top.crossrun.webview.bridge.core.pls.BridgeCallBackFunction;
import top.crossrun.webview.bridge.core.pls.WebViewBridgePlugin;
import top.crossrun.webview.bridge.core.pls.WebViewBridgePluginWithActivityLife;

/**
 * create by ruan.guangjie
 * on 2020/7/15 13:48
 * do
 */
public class TestPlugin extends WebViewBridgePlugin {
    @Override
    public void handlerBridgeMsg(String msg, BridgeCallBackFunction callBackFunction) {
        Log.e("console", msg);
        try {
            Log.e("console", "" + new File(new JSONObject(msg).getJSONObject("params").getString("dd")).exists());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        Toast.makeText(getContext(), msg, Toast.LENGTH_LONG).show();
        callBackFunction.onCallBackFunction(Calendar.getInstance().getTime().toString());
        try {
            getBridgePluginManager().loadUrl(new JSONObject(msg).getJSONObject("params").getString("url"));
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    @Override
    public String getPluginName() {
        return super.getPluginName();
    }
}
